
public class CaracFrequence implements Comparable<Object>{
	
	private int caractere;
	private int frequence;
	private CaracFrequence gauche;
	private CaracFrequence droite;
	private boolean isEmpty = true;
	private String binaryString;
		
	public String getBinaryString() {
		return binaryString;
	}

	public void setBinaryString(String binaryString) {
		this.binaryString = binaryString;
	}

	public void setCaractere(int caractere) {
		this.caractere = caractere;
	}

	public CaracFrequence getGauche() {
		return gauche;
	}

	public void setGauche(CaracFrequence gauche) {
		this.gauche = gauche;
	}

	public CaracFrequence getDroite() {
		return droite;
	}

	public void setDroite(CaracFrequence droite) {
		this.droite = droite;
	}

	public CaracFrequence(int caractere) {
		super();
		this.caractere = caractere;
		isEmpty = false;
		frequence = 1;
	}
	
	public CaracFrequence(char charNull,int frequence) {
		super();
		this.frequence = frequence;
	}
	
	public int getCaractere() {
		return caractere;
	}
	public void setCaractere(char caractere) {
		this.caractere = caractere;
	}
	public int getFrequence() {
		return frequence;
	}
	public void setFrequence(int frequence) {
		this.frequence = frequence;		
	}
	public void incFrequence() {
		this.frequence++;		
	}
	@Override
	public int compareTo(Object car) {
		//ordre croissant
		
		int freq;
		if(car instanceof CaracFrequence){
			freq = ((CaracFrequence) car).getFrequence();
		}else{
			throw new ClassCastException();
		}		
		
		if(this.frequence == freq){
			return 0;
		}else if(this.frequence <= freq){
			return -1;
		}else{
			return 1;
		}
	}
	@Override
	public boolean equals(Object car) {
		if(car instanceof CaracFrequence){
			return this.caractere == ((CaracFrequence) car).getCaractere();
		}else{
			return false;
		}
	}
	@Override
	public String toString() {
		String tempString = (char)this.caractere + " " + this.frequence;
		if (gauche != null){
			tempString += " gauche:" + gauche.toString();
		}
		if (droite != null){
			tempString += " droite:" + droite.toString();
		}
		return tempString;
	}

	public boolean isEmpty() {
		return isEmpty;
	}	
	
}
